home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / web / noweb / examples / sharpline < prev    next >
Text File  |  1995-02-24  |  655b  |  32 lines

  1. #!/bin/sh
  2. #
  3. # noweb filter to handle #line directives in noweb input
  4. #
  5. # sample usage:
  6. #
  7. #  preprocessor files | notangle -L -filter sharpline - > result.c
  8. #
  9.  
  10. nawk '
  11. BEGIN { linestart = 1 }
  12. /^(@nl|@index nl)$/ { linestart = 1; print; next }
  13. /^@text #line +[0-9]+$/ {
  14.   if (linestart)
  15.     printf "@line %d\n", $3
  16.   else
  17.     print
  18.   linestart = 0; next
  19. }
  20. /^@text #line +[0-9]+ +".*"$/ {
  21.   if (linestart) {
  22.     thisline = $3
  23.     sub(/^@text #line +[0-9]+ +/, "")
  24.     thisfile = substr($0, 2, length($0) - 2)
  25.     printf "@file %s\n@line %d\n", thisfile, thisline
  26.   } else
  27.     print
  28.   linestart = 0; next
  29. }
  30. /^@(text |quote )/ { linestart = 0 }
  31. { print }' "$@"
  32.